home *** CD-ROM | disk | FTP | other *** search
/ Shocking The Web CD-ROM / SHOCK_CD.ISO / pc / tutorial / casestdy / ch14_csa / d4vers / csaa.dir / 00002_standard routines.ls < prev    next >
Encoding:
Text File  |  1996-06-17  |  4.2 KB  |  192 lines

  1. global gHistory, gBaseURL, gReadyToGo, cgiFlag
  2.  
  3. on getLoadID theMovie
  4.   preloadNetThing(theMovie)
  5.   set currID to GetLatestNetID()
  6.   return currID
  7. end
  8.  
  9. on waitForTicks theTicks
  10.   set startTime to the timer
  11.   repeat while (startTime + theTicks) > the timer
  12.     nothing()
  13.   end repeat
  14. end
  15.  
  16. on goMovie theMovie
  17.   if not (theMovie contains ".dcr") then
  18.     set theMovie to theMovie & ".dcr"
  19.   end if
  20.   set gReadyToGo to 1
  21.   goToNetMovie(theMovie)
  22.   fadeAllSounds(200)
  23. end
  24.  
  25. on goPage thePage, target
  26.   recordHistory(thePage)
  27.   set gReadyToGo to 1
  28.   if not target then
  29.     goToNetPage(thePage)
  30.     fadeAllSounds(200)
  31.   else
  32.     goCookiePage(thePage)
  33.   end if
  34. end
  35.  
  36. on getFileName theURL
  37.   repeat with i = the number of chars in theURL down to 1
  38.     if (char i of theURL = "/") or (char i of theURL = ":") then
  39.       set rVal to char i + 1 to the number of chars in theURL of theURL
  40.       exit repeat
  41.     end if
  42.   end repeat
  43.   return rVal
  44. end
  45.  
  46. on getCurrLabel
  47.   set lastLine to the number of lines in the labelList - 1
  48.   repeat with i = 1 to lastLine
  49.     if the frame < label(line i of the labelList) then
  50.       if i > 1 then
  51.         return line i - 1 of the labelList
  52.       else
  53.         return EMPTY
  54.       end if
  55.       exit
  56.     end if
  57.   end repeat
  58.   return line lastLine of the labelList
  59. end
  60.  
  61. on goCookiePage thePage
  62.   put thePage
  63.   if not cgiFlag then
  64.     getNetText("cgi/cookie_set.cgi?cookieName=nextPage;cookieValue=" & thePage)
  65.     set cgiFlag to 1
  66.     set gReadyToGo to 1
  67.   end if
  68. end
  69.  
  70. on checkCGI
  71.   if cgiFlag = 1 then
  72.     if NetDone() = 1 then
  73.       set cgiFlag to 0
  74.       set gReadyToGo to 0
  75.       return NetTextResult()
  76.       exit
  77.     end if
  78.   end if
  79.   return 0
  80. end
  81.  
  82. on fadeAllSounds fadeDuration
  83.   if soundBusy(1) or soundBusy(2) then
  84.     set lPlaying to 1
  85.   end if
  86.   if soundBusy(1) then
  87.     sound fadeOut 1, fadeDuration
  88.   end if
  89.   if soundBusy(2) then
  90.     sound fadeOut 2, fadeDuration
  91.   end if
  92.   if lPlaying then
  93.     waitForTicks(fadeDuration)
  94.   end if
  95. end
  96.  
  97. on recordHistory theURL
  98.   if not gHistory then
  99.     set gHistory to []
  100.   end if
  101.   set index to getPos(gHistory, theURL)
  102.   if index then
  103.     deleteAt(gHistory, index)
  104.   end if
  105.   append(gHistory, theURL)
  106. end
  107.  
  108. on allSprites pup, vis, start, stop
  109.   if not start then
  110.     set start to 1
  111.   end if
  112.   if not stop then
  113.     set stop to 48
  114.   end if
  115.   repeat with i = start to stop
  116.     if not (pup = -1) then
  117.       puppetSprite(i, pup)
  118.     end if
  119.     if not (vis = -1) then
  120.       set the visible of sprite i to vis
  121.     end if
  122.   end repeat
  123. end
  124.  
  125. on distance point1, point2
  126.   set xDiff to the locH of point2 - the locH of point1
  127.   set yDiff to the locV of point2 - the locV of point1
  128.   set dist to sqrt(power(xDiff, 2) + power(yDiff, 2))
  129.   return dist
  130. end
  131.  
  132. on makeTriangle radLength, radLoc, twoPoint
  133.   set thirdPoint to point(the locH of radLoc, the locV of radLoc - radLength)
  134.   set thirdSide to distance(thirdPoint, twoPoint)
  135.   return thirdSide
  136. end
  137.  
  138. on pythagoras radLen, sideLen
  139.   set rvSquare to power(radLen, 2) - power(sideLen, 2)
  140.   return integer(sqrt(rvSquare))
  141. end
  142.  
  143. on radians degrees
  144.   set rVal to degrees * (PI / 180)
  145.   return rVal
  146. end
  147.  
  148. on degrees radians
  149.   set rVal to radians * 180 / PI
  150.   return rVal
  151. end
  152.  
  153. on spriteCenter theSprite
  154.   set rVal to the right of sprite theSprite - integer(the width of sprite theSprite / 2)
  155.   return rVal
  156. end
  157.  
  158. on getFollowAngle theSprite, rXpoint
  159.   global oldMousePoint, oldAngle, oldSprite
  160.   set mousePoint to point(the mouseH, the mouseV)
  161.   if mousePoint <> getaProp(oldMousePoint, theSprite) then
  162.     if not rXpoint then
  163.       set rXpoint to spriteCenter(theSprite)
  164.     end if
  165.     if the mouseH > rXpoint then
  166.       set mult to 1
  167.     else
  168.       set mult to -1
  169.     end if
  170.     set radLength to distance(the loc of sprite theSprite, mousePoint)
  171.     set thirdSide to makeTriangle(radLength, the loc of sprite theSprite, mousePoint) / 2
  172.     set chordLen to pythagoras(radLength, thirdSide)
  173.     setaProp(oldMousePoint, theSprite, mousePoint)
  174.     if chordLen <> 0 then
  175.       set rVal to atan(thirdSide / chordLen) * (360 / PI)
  176.       if not integer(rVal) then
  177.         if string(rVal) contains "-" then
  178.           set rVal to 180
  179.         end if
  180.       else
  181.         set rVal to rVal * mult
  182.       end if
  183.     else
  184.       set rVal to 180
  185.     end if
  186.     setaProp(oldAngle, theSprite, rVal)
  187.   else
  188.     set rVal to getaProp(oldAngle, theSprite)
  189.   end if
  190.   return rVal
  191. end
  192.